function serviceHeader() {
  return new ServiceHeader(
    1,
    "Google",
    "Google's free online language translation service instantly translates text and web pages." +
      Const.NL2 +
      serviceHost() +
      Const.NL2 +
      "\u00a9 2020 Google",
    Capability.TRANSLATE | Capability.DETECT_LANGUAGE | Capability.LISTEN
  );
}
function serviceHost(a, b, c) {
  return "https://translate.google." + (Options.GoogleDomain || "com");
}
function serviceLink(a, b, c) {
  var h = serviceHost() + "/";
  a &&
    ((b = isLanguage(b) ? codeFromLanguage(b) : "auto"),
    (c = isLanguage(c) ? codeFromLanguage(c) : "auto"),
    (h += format("#{0}/{1}/{2}", b, c, encodeGetParam(a))));
  return h;
}
SupportedLanguages = [
  -1,
  "auto",
  "af",
  "az",
  "sq",
  "ar",
  "hy",
  "eu",
  "be",
  "bg",
  "ca",
  "zh-CN",
  "zh-TW",
  "hr",
  "cs",
  "da",
  "nl",
  "en",
  "et",
  "fi",
  "tl",
  "fr",
  "gl",
  "de",
  "el",
  "ht",
  "iw",
  "hi",
  "hu",
  "is",
  "id",
  "it",
  "ga",
  "ja",
  "ka",
  "ko",
  "lv",
  "lt",
  "mk",
  "ms",
  "mt",
  "no",
  "fa",
  "pl",
  "pt",
  "ro",
  "ru",
  "sr",
  "sk",
  "sl",
  "es",
  "sw",
  "sv",
  "th",
  "tr",
  "uk",
  "ur",
  "vi",
  "cy",
  "yi",
  "eo",
  "hmn",
  "la",
  "lo",
  "kk",
  "uz",
  "si",
  "tg",
  "te",
  "km",
  "mn",
  "kn",
  "ta",
  "mr",
  "bn",
  "tt",
];
function tk(a) {
  function b(a, b) {
    for (var d = 0; d < b.length - 2; d += 3) {
      var c = b.charAt(d + 2),
        c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
        c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
      a = "+" == b.charAt(d) ? (a + c) & 4294967295 : a ^ c;
    }
    return a;
  }
  for (
    var c = (Options.GoogleTkk || "0.0").split("."),
      h = Number(c[0]) || 0,
      g = [],
      d = 0,
      e = 0;
    e < a.length;
    e++
  ) {
    var f = a.charCodeAt(e);
    128 > f
      ? (g[d++] = f)
      : (2048 > f
          ? (g[d++] = (f >> 6) | 192)
          : (55296 == (f & 64512) &&
            e + 1 < a.length &&
            56320 == (a.charCodeAt(e + 1) & 64512)
              ? ((f = 65536 + ((f & 1023) << 10) + (a.charCodeAt(++e) & 1023)),
                (g[d++] = (f >> 18) | 240),
                (g[d++] = ((f >> 12) & 63) | 128))
              : (g[d++] = (f >> 12) | 224),
            (g[d++] = ((f >> 6) & 63) | 128)),
        (g[d++] = (f & 63) | 128));
  }
  a = h;
  for (d = 0; d < g.length; d++) (a += g[d]), (a = b(a, "+-a^+6"));
  a = b(a, "+-3^+b+-f");
  a ^= Number(c[1]) || 0;
  0 > a && (a = (a & 2147483647) + 2147483648);
  a %= 1e6;
  return a.toString() + "." + (a ^ h);
}
function serviceDetectLanguageRequest(a) {
  a = limitSource(a);
  var b = tk(a);
  a = encodeUriParam(a);
  var c = a.length > Const.MAX_URI_LEN ? HttpMethod.POST : HttpMethod.GET;
  return new RequestData(
    c,
    "/translate_a/single?client=gtx&sl=auto&dt=ld&ie=UTF-8&oe=UTF-8&tk=" +
      b +
      (c === HttpMethod.POST ? "" : "&q=" + a),
    c === HttpMethod.POST ? "q=" + a : null
  );
}
function serviceDetectLanguageResponse(a) {
  a = parseJSON(a);
  return getSourceLanguage(a);
}
function serviceTranslateRequest(a, b, c) {
  a = limitSource(a);
  var h = tk(a);
  a = encodeUriParam(a);
  var g = a.length > Const.MAX_URI_LEN ? HttpMethod.POST : HttpMethod.GET;
  b = format(
    "/translate_a/single?client=gtx&sl={0}&tl={1}&hl={2}&dt=bd&dt=t&dt=ld&dt=rm&ie=UTF-8&oe=UTF-8&tk={3}",
    codeFromLanguage(b),
    codeFromLanguage(c),
    Options.LanguageCode,
    h
  );
  g === HttpMethod.GET && (b += "&q=" + a);
  return new RequestData(g, b, g === HttpMethod.POST ? "q=" + a : null);
}
function serviceTranslateResponse(a, b, c, h) {
  a = parseJSON(b);
  var g = (b = ""),
    d,
    e;
  if (a) {
    var f = a[0];
    if (f)
      for (d = 0; d < f.length; d++)
        (e = f[d]) &&
          0 !== e.length &&
          ((b += e[0] || ""),
          2 < e.length && d === f.length - 1 && (g = e[2] || ""));
    if ((f = a[1]))
      for (d = 0; d < f.length; d++)
        if (((e = f[d]), !(3 > e.length))) {
          b += Const.NL2 + e[0] + ":";
          var l = e[2];
          for (e = 0; e < l.length; e++) {
            var k = l[e];
            1 < k.length &&
              ((b += Const.NL + "    " + k[0]),
              (k = k[1]) && 0 < k.length && (b += " (" + k.join(", ") + ")"));
          }
        }
    isLanguage(c) || (c = getSourceLanguage(a));
  }
  return new ResponseData(b, c, h, g);
}
function getSourceLanguage(a) {
  return !a || 9 > a.length
    ? UNKNOWN_LANGUAGE
    : (a = a[8]) && 0 !== a.length
    ? languageFromCode(a[0][0])
    : UNKNOWN_LANGUAGE;
}
function serviceListenRequest(a, b, c) {
  a = format(
    "/translate_tts?ie=UTF-8&q={0}&tl={1}&client=gtx&tk={2}",
    encodeGetParam(a),
    codeFromLanguage(b),
    tk(a)
  );
  c && (a += "&ttsspeed=0.24");
  return new RequestData(HttpMethod.GET, a);
}
